//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================


//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - S+S Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.CompositeUI.SmartParts;
using Microsoft.Practices.CompositeUI.WPF;
using Microsoft.Practices.ObjectBuilder;
using System.Windows.Controls;
using System.Windows.Media.Animation;
using LitwareHR.Infrastructure.Interface;
using LitwareHR.PublicApp.WinUX.Properties;
using System.Drawing;
using System.Globalization;
 
namespace LitwareHR.PublicApp.WinUX
{
    /// <summary>
    /// Interaction logic for HeaderView.xaml
    /// </summary>
    public partial class HeaderView : System.Windows.Controls.UserControl, IHeaderView, IDisposable
    {
        /// <summary>
        /// Initialize a new instance of <see cref="HeaderView"/>.
        /// <summary>
        public HeaderView()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(OnLoad);
        }

        /// <summary>
        /// Called when WPF has loaded the control and is ready to display it.
        /// <summary>
        /// <param name="sender">Source of the event</param>
        /// <param name="e">Extra information about the event</param>
        void OnLoad(object sender, RoutedEventArgs e)
        {
            _presenter.OnViewReady();            
        }

        #region IHeaderView Members

        /// <summary>
        /// Set Default settings for Header
        /// </summary>
        public void SetAnimationDefaults()
        {
            plugCanvasBackward.Visibility = Visibility.Hidden;
            plugCanvasForward.Visibility = Visibility.Hidden;
            sockectCanvas.Visibility = Visibility.Hidden;
            connectedCanvas.Visibility = Visibility.Visible;
        }
        /// <summary>
        /// Sets Header Image
        /// </summary>
        /// <param name="image"></param>
        public void SetImage(BitmapSource image)
        {
            HeaderImage.Source = image;
            HeaderImage.Visibility = Visibility.Visible;
            ProgressText.Visibility = Visibility.Hidden;           
        }

        /// <summary>
        /// Show Progress while downloading Image (New Logo)
        /// </summary>
        /// <param name="progress"></param>
        public void ShowProgress(int progress)
        {
            HeaderImage.Visibility = Visibility.Hidden;
            ProgressText.Text = String.Format(CultureInfo.InvariantCulture, Properties.Resources.HeaderView_DownloadImageProgress, progress.ToString(CultureInfo.InvariantCulture));
        }

        /// <summary>
        /// This method is called to display Animation
        /// from Disconnected to Connected
        /// </summary>
        public void ShowConnectAnimation()
        {
            plugCanvasBackward.Visibility = Visibility.Hidden;
            plugCanvasForward.Visibility = Visibility.Visible;            
            Storyboard story = (Storyboard)plugCanvasForward.FindResource("storyforwardkey");
            story.Completed += new EventHandler(story_Completed);
            story.Begin(plugCanvasForward);                                  
        }

        /// <summary>
        /// This method is called on completion of storyboard "storyforwardkey" (for Disconnected to Connected)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void story_Completed(object sender, EventArgs e)
        {
            sockectCanvas.Visibility = Visibility.Hidden;
            plugCanvasForward.Visibility = Visibility.Hidden;
            connectedCanvas.Visibility = Visibility.Visible;            
        }

        /// <summary>
        /// This method is called when the status is changed from Connected to Disconnected.
        /// </summary>
        public void ShowDisconnectAnimation()
        {
            SetAnimationDefaults();
            connectedCanvas.Visibility = Visibility.Visible;
            plugCanvasForward.Visibility = Visibility.Hidden;
            plugCanvasBackward.Visibility = Visibility.Hidden;
            BackwardStory();
        }

        /// <summary>
        /// This method is called on completion of storyboard "storybackwardkey" (for Connected to Disconnected)
        /// </summary>
        private void BackwardStory()
        {
            Storyboard storybackward = (Storyboard)plugCanvasBackward.FindResource("storybackwardkey");
            storybackward.Begin(plugCanvasBackward);
            connectedCanvas.Visibility = Visibility.Hidden;
            sockectCanvas.Visibility = Visibility.Visible;
            plugCanvasBackward.Visibility = Visibility.Visible;
        }

        #endregion
    }
}

